package 剑指offer;

public class Offer53_JZ37_2 {
    public int missingNumber(int[] nums) {
        int i;
        for (i=0; i<nums.length; i++) {
            if (i != nums[i]) {
                return i;
            }
        }
        return i;
    }

    public int missingNumber2(int[] nums) {
        int left = 0, right = nums.length-1;
        while (left <= right) {
            int mid = (left+right) / 2;
            if (nums[mid] == mid) {
                left = mid+1;
            } else {
                right = mid-1;
            }
        }
        return left;
    }
}
